package com.snail.billing.page;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.ViewGroup.LayoutParams;
import android.webkit.WebView;
import android.widget.TextView;

import com.android.os.MyEngine;
import com.android.util.ResUtil;
import com.snail.billing.Resource;
import com.snail.billing.os.DialogPage;
import com.snail.billing.util.WebViewOption;

public class WebViewPage extends DialogPage implements View.OnClickListener {

	public static final String TITLE = "title";
	public static final String URL = "url";

	private TextView textTitle;
	private View buttonBack;

	private WebView webView;

	private String titleString;
	private String urlString;

	@Override
	public int createLayoutId() {
		return ResUtil.getLayoutId(Resource.layout.snailbilling_webview_activity);
	}

	@Override
	public LayoutParams getLayoutParams() {
		int screenWidth = getContext().getResources().getDisplayMetrics().widthPixels;
		int screenHeight = getContext().getResources().getDisplayMetrics().heightPixels;
		int screenTop = MyEngine.getEngine().getActivity().getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
		return new ViewGroup.LayoutParams(screenWidth, screenHeight - screenTop);
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		titleString = getPageArgs().getString(TITLE);
		urlString = getPageArgs().getString(URL);
		textTitle = (TextView) findViewById(ResUtil.getViewId(Resource.id.snailbilling_title_text));
		textTitle.setText(titleString);
		buttonBack = findViewById(ResUtil.getViewId(Resource.id.snailbilling_title_button_back));
		buttonBack.setOnClickListener(this);
		//
		webView = (WebView) findViewById(ResUtil.getViewId(Resource.id.snailbilling_webview_webview));
		WebViewOption.option(webView);
		webView.loadUrl(urlString);
	}

	@Override
	public void onClick(View v) {
		if (v.equals(buttonBack)) {
			getPageManager().backward();
		}
	}

}
